/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.dby.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.thinkgem.jeesite.common.persistence.ResponseResult;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.dby.entity.EntPerson;
import com.thinkgem.jeesite.modules.dby.service.EntPersonService;

/**
 *
 * 企业基本信息Controller
 * @author dby
 * @version 2020-06-25
 */
@Controller
@RequestMapping(value = "${adminPath}/dby/entPerson")
public class EntPersonController extends BaseController {

	@Autowired
	private EntPersonService entPersonService;
/*
*
*
* 新创建dev 分支
*  在删除一部分代码之后，加入新功能代码
*水电费
*胜多负少的 水电费
* */

	/*
	 * 演示git操作
	 *
	 *
	 *
	 *
	 *
	 *
	 *
	 *
	 *
	 *
	 *
	 *
	 * */
	@ModelAttribute
	public EntPerson get(@RequestParam(required=false) String id) {
		EntPerson entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = entPersonService.get(id);
			entity = entPersonService.get(id);
		}
		if (entity == null){
			entity = new EntPerson();
		}
		return entity;
	}
	
	@RequiresPermissions("dby:entPerson:view")
	@RequestMapping(value = {"list", ""})
	public String list(EntPerson entPerson, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<EntPerson> page = entPersonService.findPage(new Page<EntPerson>(request, response), entPerson); 
		model.addAttribute("page", page);
		return "modules/dby/entPersonList";
	}

	@RequiresPermissions("dby:entPerson:view")
	@RequestMapping(value = "form")
	public String form(EntPerson entPerson, Model model) {
		model.addAttribute("entPerson", entPerson);
		return "modules/dby/entPersonForm";
	}

	@RequiresPermissions("dby:entPerson:edit")
	@RequestMapping(value = "save")
	public String save(EntPerson entPerson, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, entPerson)){
			return form(entPerson, model);
		}
		entPersonService.save(entPerson);
		addMessage(redirectAttributes, "保存企业信息成功");
		return "redirect:"+Global.getAdminPath()+"/dby/entPerson/?repage";
	}
	
	@RequiresPermissions("dby:entPerson:edit")
	@RequestMapping(value = "delete")
	public String delete(EntPerson entPerson, RedirectAttributes redirectAttributes) {
		entPersonService.delete(entPerson);
		addMessage(redirectAttributes, "删除企业信息成功");
		return "redirect:"+Global.getAdminPath()+"/dby/entPerson/?repage";
	}


	@RequiresPermissions("dby:entPerson:view")
	@RequestMapping(value = "form1")
	public String form1(EntPerson entPerson
			, Model model) {
		model.addAttribute("entPerson", entPerson);
		return "modules/dby/entPersonForm";
	}

	@RequestMapping(value = "form2")
	public String form1(EntPerson entPerson
			, @RequestParam(value = "userName1") String un
			, Model model) {
		System.out.println(un);
		model.addAttribute("entPerson", entPerson);
		return "modules/dby/entPersonForm";
	}

	@ResponseBody
	@RequestMapping(value = "form3",method = RequestMethod.GET)
	public ResponseResult form3(@RequestParam(value = "id") String id) {
			EntPerson entPerson = entPersonService.get(id);
		return ResponseResult.success(entPerson);
	}

	@ResponseBody
	@RequestMapping(value = "form4")
	public String form3(
			@RequestParam(value = "userName") String userName
	,@RequestParam(value = "id") String id
	) {

		System.out.println(id);
		System.out.println(userName);

		return "modules/dby/entPersonForm";
	}

}